package com.sgb.kjwl.viewmodel.pick;

import androidx.lifecycle.ViewModel;

import com.sgb.kjwl.api.APIManager;
import com.sgb.kjwl.view.ui.fragment.pick.PickCategoryFragment;
import com.swgk.core.base.api.ICallBack;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.dialog.DialogHelper;
import com.swgk.core.util.PickSelectEntity;
import com.swgk.core.view.selection.CommonPopEntity;

import java.util.HashMap;
import java.util.List;


public class PickCategoryFragmentModel extends ViewModel {

    PickCategoryFragment fragment;

    public void setActivity(PickCategoryFragment pickCategoryFragment) {
        fragment = pickCategoryFragment;
    }

    public void getFilterTypeData() {
        DialogHelper.showProgressDialog2(fragment.getActivity(), null, "加载中", 0, true, null, false);
        APIManager.getInstance().getPickAPI().tenderNewTypeList().enqueue(new ICallBack<BaseEntity<List<PickSelectEntity>>>() {
            @Override
            public void onSuccess(BaseEntity<List<PickSelectEntity>> data) {
                DialogHelper.dismissProgressDialog();
                if (data == null || data.getState() == null) {
                    return;
                }

                if (data.getState().equals(APIManager.RESPONSE_OK)) {
                    fragment.setTypeDatas(data.getData());
                }
            }
        });
    }

    //新增类型过滤接口
    public void getTenderGoodsCategoryAllList(String category) {
        DialogHelper.showProgressDialog2(fragment.getActivity(), null, "加载中", 0, true, null, false);
        HashMap map = new HashMap();
        map.put("type", category);
        APIManager.getInstance().getPickAPI().getTenderGoodsCategoryAllListNew(map).enqueue(new ICallBack<BaseEntity<List<CommonPopEntity>>>() {
            @Override
            public void onSuccess(BaseEntity<List<CommonPopEntity>> data) {
                DialogHelper.dismissProgressDialog();
                if (data == null || data.getState() == null) {
                    return;
                }

                if (data.getState().equals(APIManager.RESPONSE_OK)) {
                    fragment.setTenderGoodsCategoryAllList(data.getData());
                }
            }
        });
    }
}
